<template>
	<uni-indexed-list :options="agents" @click="bindClick" />
</template>

<script>
	
	import store from '@/store/store.vue'
	import uniIndexedList from '@/components/uni-indexed-list/uni-indexed-list.vue'
	export default {
		onLoad(){
			let _this = this
			let open_id = getApp().globalData.open_id
			uni.request({
				url: store.url + '/user/get_new_agent?openId=' + open_id,
				method: 'GET',
				header: {				
				},
				success: (res) => {			
					if(res.data.status == 'success'){
						_this.data_raw = res.data.message
						let data_parse = []
						for(let i = 0; i < _this.data_raw.length; i++){
							data_parse[i] = {'name': _this.data_raw[i].user_name, 'headImg': _this.data_raw[i].img_url}
						}
						_this.agents = [{data:data_parse}]
					}else{
						uni.showModal({
							title: '提示',
							content: '错误: ' + res.data.message
						});	
					}																      
				},
				fail: (res)=>{
					uni.showModal({
						title: '提示',
						content: '访问服务器失败: ' + res.data.message
					});						
				}
			});	
		},
		components: {
			uniIndexedList
		},
		data() {
			return {
				agents: [{}],
				data_raw: []
			}
		},
		methods: {			
			bindClick(e) {
				let _this = this			
				let param = e.item.name
				let user_id = 0
				for(let i = 0; i < _this.data_raw.length; i++){
						if(_this.data_raw[i].user_name == param){
							user_id = _this.data_raw[i].id
						}
				} 
				uni.navigateTo({
					url: '/pages/newAgent/detail?param=' + encodeURIComponent(JSON.stringify(user_id))
				})
			}
		}
	}
</script>

<style></style>